function MinePublishObjController(analyseId){
	
	this.analyseId = analyseId;
	/**
	 * 初始化全部流程列表
	 */
	this.initAllFlowGrid = function(data){
		if(!this.flowGrid){
			this.flowGrid = $('#mine-publish-all-grid').datagrid({
				datatype : "local",
//				data : data,
				height : $('#publish-mine-layout').parent().height() - 85,
				width : $('#mine-publish-all-grid').parent().width()-2,
				rownumbers : true,
				hidegrid : false,
				autowidth:true,
				resizable:false,
				striped : true,
				viewrecords : true,
				loadui:'disable',
				colNames : [ 'id', 
				             'appId',
				             'parentId',
				             TempoUtils.locale("mine.publish-all-flow-grid-column-name"),
				             TempoUtils.locale("mine.publish-all-flow-grid-column-author"),
				             TempoUtils.locale("mine.publish-all-flow-grid-column-createtime"),
				             TempoUtils.locale("mine.publish-all-flow-grid-column-updatetime"),
				             TempoUtils.locale("mine.publish-grid-column-opt")],
				colModel : [{
							name : 'id',
							index : 'id',
							hidden : true
						},{
							name : 'appId',
							index : 'appId',
							hidden : true,
						},{
							name : 'parentId',
							index : 'parentId',
							hidden : true
						},{
							name : 'name',
							index : 'name',
							resizable:false,
							sortable : false,
							formatter : function(obj, grid, rows, state) {
								return obj;
							}
						},{
							name : 'author',
							index : 'author',
							width : 80,
							sortable:false
						},{
							name : 'createTime',
							index : 'createTime',
							width : 130,
							align : 'center',
							resizable:false,
							sortable : false,
							formatter : function(obj, grid, rows, state) {
								if(obj && $.isNumeric(obj)){
									return DateUtils.formatDateTime(new Date(obj), 'yyyy-MM-dd HH:mm:ss');
								}
								return '';
							}
						},{
							name : 'visitTime',
							index : 'visitTime',
							width : 130,
							align : 'center',
							resizable:false,
							sortable : false,
							formatter : function(obj, grid, rows, state) {
								if(obj && $.isNumeric(obj)){
									return DateUtils.formatDateTime(new Date(obj), 'yyyy-MM-dd HH:mm:ss');
								}
								return '';
							}
						},{
							name : '',
							index : '',
							sortable : false,
							width : 100,
							align : 'center',
							fixed : false,
							buttons:[{
								id : "edit",
								icon : 'ui-icon tempo-ui-icon tempo-ui-icon-publish',
								title: TempoUtils.locale("mine.publish-all-flow-grid-optpublish"),
								click:function(e,dt){	     
									var rowid = dt.rowId;
									var row = dt.rowData;
									//获得所有发布的列表 标注是否同流程 
									publishReplaceService(row,publishFlow);//替换同源服务
									
								}
							}, {
								id : "view",
								icon: "ui-icon tempo-ui-icon tempo-ui-icon-linkage",
								title: TempoUtils.locale("mine.publish-published-flow-grid-optview"),
								click:function(e,dt){	     
									var row = dt.rowData;
									viewPublishFlow(row);
								}
							}]
						}]
			});
		}
		this.flowGrid.jqGrid('clearGridData');
		if(data && data.length > 0){
			for (var i = 0; i < data.length; i++) {
				this.flowGrid.jqGrid('addRowData', data[i].id, data[i], i)
			}
		}
	}
	
	/**
	 * 发布时显示所有服务列表
	 */
	var publishReplaceService = function(row, callback ){
		var form = $('<form>');
		var table = $('<table>').addClass('formLayout').appendTo(form);
		var tbody = $('<tbody>').appendTo(table);
		//发布名称
		var tr = $('<tr>').appendTo(tbody);
		var labelTd = $('<td>').appendTo(tr);
		var label = $('<label>').attr('for', 'publishName').text(TempoUtils.locale("mine.publish-all-flow-label-publishName")).appendTo(labelTd);
		var inputTd = $('<td>').appendTo(tr);
		var label = $('<input>').attr('name', 'publishName').appendTo(inputTd).validatebox({validator: true, required: true, maxLength:50,autofill:false });
		//是否更新同源服务
		tbody.append($("<tr><td >"+TempoUtils.locale("mine.updateCognate")+"</td> " +
							"<td>" +
							"<input id='isCognate' type='radio' class='tempo-radio' name='updCognateService' checked='true' value='1'>"+
							"<label for='isCognate' class='ui-label'>"+TempoUtils.locale("mine.exportyes")+"</label>"+		
							"<input id='notCognate' type='radio' class='tempo-radio' name='updCognateService' checked='false' value='0'>"+
							"<label for='notCognate' class='ui-label' style='margin-left: 85px;'>"+TempoUtils.locale("mine.exportno")+"</label></td>" +
							"</tr>"));
				
		var table = $('<table id="'+ TempoUtils.uuid()+'"></table>');
		
		var div = $("<div/>").append(form);
		div.append(table);
		//注
		var span = $("<span style='color:blue'>"+TempoUtils.locale("mine.cognateTips")+"</span>");
		div.append(span);
		$("#tempDialog").remove();
		var dialog = $('<div id="tempDialog" style="overflow:hidden;padding-bottom: 0px!important;">').append(div).dialog({
			width : 450,
			height:500,
			autoOpen:true,
			title: TempoUtils.locale("mine.publish-all-flow-label-publishName"),
			modal:true,
			close : function(){
				dialog.dialog("destroy");
			},
			open : function(){
				$(this).find('input[name="publishName"]').val(row.name);				
				$(this).find(':radio[name="updCognateService"]').click(function(e){
					if($(this).val() == "1"){
						table.find(":checkbox").removeAttr("disabled");
						form.next().find("th").css("color","#5b6e85");
						form.next().find("td").css("color","#333");
					}else{
						form.next().find("th,td").css("color","#d0d2d5");
						table.find(":checkbox").attr("disabled","disabled");
					}
				});
				$(this).find('#notCognate').prop("checked",true);
				table.datagrid({
					url:contextPath+"/api/ai/mine/publish/listAllService?id="+row.id+"&&themeId="+analyseId,
					datatype : "json",
					height : 150,
					width : 400,
					rownumbers:true,
					rowNum:1000,
					striped : true,
					searchBar:true,
					searchBarOptions:{
						onSearch:function(value){
							value = value == ""?null:value;
							table.datagrid("reloadGrid",{name:value},true);
						} 		
					},
					colNames : [ "id",TempoUtils.locale("mine.cognate_service"),TempoUtils.locale("mine.sftlc"),TempoUtils.locale("mine.cognate_update")],
					colModel : [{
								name : 'id',
								index : 'id',
								width : '120px',
								hidden : true	
							},{
								name : 'name',
								index : 'name',
								width : '120px',
								hidden : false,
								sortable : false,
							},{
								name : 'sameflow',
								index : 'sameflow',
								width : '120px',
								hidden : false,
								sortable : false,
								formatter:function(v){
									if(v == "1"){
										return TempoUtils.locale("mine.y");
									}else{
										return TempoUtils.locale("mine.n");
									}
								}
							},{
								name : 'checkcolumn',
								index : 'checkcolumn',
								width : '120px',
								hidden : false,
								sortable : false,
								formatter:function(v,row,rowdata){	
									var id = TempoUtils.uuid();
									return "<input type='checkbox' id='"+id+"' checked=false  value='"+rowdata.id+"' class='tempo-checkbox'>"+
										"<label for='"+id+"' class='ui-label'> </label>";
								}
							}
					],
					loadComplete:function(){
						table.find(":checkbox").prop("checked",false);
						if(dialog.find('#notCognate').prop("checked")){
							form.next().find("th,td").css("color","#d0d2d5");
							table.find(":checkbox").attr("disabled","disabled");
						}
					}
			 });				
			},
			buttons:[{
				text:TempoUtils.locale("mine.publish-all-flow-dialog-okbtn"),
				click:function(){
					if(!dialog.find('form').formValidate()){
						return;
					}
					var name = dialog.find('input[name="publishName"]').val().trim();
					var isUpd = dialog.find('input:radio:checked[name="updCognateService"]').val();
					var list = [];
					if(isUpd == "1"){
						var checkedOb = table.find(":checkbox:checked");
						for(var i = 0 ; i < checkedOb.length ; i++){
							list.push($(checkedOb[i]).val());
						}
					}
					if(isUpd == "1" && list.length == 0){
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-listLenZero"), height : 280});
						return;
					}
					if(name && name.length > 0){
							callback(dialog, row, name,list);
					}else{
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-emptyname"), height : 280});
					}
				}
			},{
				text:TempoUtils.locale("mine.publish-all-flow-dialog-cancelbtn"),
				click:function(){
					dialog.dialog("destroy");
				}
			}]
		})
	}
	
	/**
	 * 流程列表发布/重命名事件
	 */
	var publishEvent = function(row, callback){
		var form = $('<form>');
		var table = $('<table>').addClass('formLayout').appendTo(form);
		var tbody = $('<tbody>').appendTo(table);
		var tr = $('<tr>').appendTo(tbody);
		var labelTd = $('<td>').appendTo(tr).addClass('formLayoutTit');
		var label = $('<label>').attr('for', 'publishName').text(TempoUtils.locale("mine.publish-all-flow-label-publishName")).appendTo(labelTd);
		var inputTd = $('<td>').appendTo(tr);
		var label = $('<input>').attr('name', 'publishName').appendTo(inputTd).validatebox({validator: true, required: true, maxLength:50,autofill:false });
		var dialog = $('<div>').append(form).dialog({
			width : 300,
			minHeight: 100,
			autoOpen:true,
			title: TempoUtils.locale("mine.publish-all-flow-label-publishName"),
			modal:true,
			close : function(){
				dialog.dialog("destroy");
			},
			open : function(){
				$(this).find('input[name="publishName"]').val(row.name);
			},
			buttons:[{
				text:TempoUtils.locale("mine.publish-all-flow-dialog-okbtn"),
				click:function(){
					if(!dialog.find('form').formValidate()){
						return;
					}
					var name = dialog.find('input[name="publishName"]').val().trim();
					if(name && name.length > 0){
							callback(dialog, row, name);
					}else{
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-emptyname"), height : 280});
					}
				}
			},{
				text:TempoUtils.locale("mine.publish-all-flow-dialog-cancelbtn"),
				click:function(){
					dialog.dialog("destroy");
				}
			}]
		})
	}
	
	/**
	 * 发布流程 --list为需要更新同源服务的列表 若length为null 则不走同源
	 */
	var publishFlow = function(dialog, data, name,list){
		var flowId = data.id;
		var mask = $("<div/>").tempoprogressbar();
		$.ajax({
			url:contextPath+"/api/ai/mine/publish/savePublish",
			data:{
				flowId: flowId,
				sceneId : analyseId,
				name : name,
				list:list == null?"":list.toString()
			},
			dataType:'json',
			type:'post',
			success:function(result){
				mask.tempoprogressbar('close');
				if(result && result.success){
					dialog.dialog("destroy");
					var data = result.data;
//					$('#mine-published-grid').jqGrid('addRowData',data.id, data, 0);
					//增加之后改为重新加载表格
					$.ajax({
						url:contextPath+"/api/ai/mine/publish/listPublish?time=" + new Date().getTime(),
						data:{
							themeId: analyseId
						},
						dataType:'json',
						type:'post',
						success:function(result){
							initPublishFlowGrid(result); 
						}
					});
				}else{
					var errorCode = result.data;
					//保存失败
					if(errorCode == '0'){
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-savefailed"), height : 280});
					}else if(errorCode == '-1'){
						//名称重复
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-nameexists"), height : 280});
					}else{
						$("<div/>").alert({msg : errorCode == null?TempoUtils.locale("mine.publish-savefailed"):errorCode, height : 280});
					}
				}
			}
		});
	}
	
	/**
	 * 初始化全部流程列表
	 */
	this.initPublishFlowGrid = function(data){
		if(!this.grid){
			this.grid = $('#mine-published-grid').datagrid({
				datatype : "local",
				data : data,
				height : $('#publish-mine-layout').parent().height() - 85,
				width : $('#mine-published-grid').parent().width()-5,
				rownumbers : true,
				shrinkToFit : true,
				striped : true,
				resizable:false,
				loadui:'disable',
				viewrecords : true,
				colNames : [ 'id', 
				             TempoUtils.locale("mine.publish-published-flow-grid-column-name"),
				             'author',
				             TempoUtils.locale("mine.publish-published-flow-grid-column-author"),
				             TempoUtils.locale("mine.publish-published-flow-grid-column-createtime"),
				             TempoUtils.locale("mine.publish-published-flow-grid-column-relatedJobs"),
				             TempoUtils.locale("mine.publish-published-flow-grid-column-relatedServices"),
				             TempoUtils.locale("mine.publish-grid-column-opt")],
				colModel : [{
							name : 'id',
							index : 'id',
							hidden : true
						},{
							name : 'name',
							index : 'name',
							resizable:false,
							sortable : false,
							formatter : function(obj, grid, rows, state) {
								return obj;
							}
						},{
							name : 'author',
							index : 'author',
							hidden : true
						},{
							name : 'authorName',
							index : 'authorName',
							width : 60,
							sortable:false
						},{
							name : 'publishTime',
							index : 'publishTime',
							resizable:false,
							sortable : false,
							align : 'center',
							width : 100,
							formatter : function(obj, grid, rows, state) {
								if(obj && $.isNumeric(obj)){
									return DateUtils.formatDateTime(new Date(obj), 'yyyy-MM-dd HH:mm:ss');
								}
								return obj;
							}
						},{
							name : 'relatedJobs',
							resizable : false,
							sortable : false,
							align : 'center',
							width : 120
						},{
							name : 'relatedServices',
							resizable : false,
							sortable : false,
							align : 'center',
							width : 120
						},{
							name : 'opt',
							index : '',
							sortable : false,
							align : 'center',
							fixed : false,
							width : 90,
							buttons:[{
								id : "rename",
								icon: "ui-icon tempo-ui-icon tempo-ui-icon-rename",
								title:  TempoUtils.locale("mine.publish-published-flow-grid-optrename"),
								click:function(e,dt){	
									var d = $('#mine-published-grid').datagrid('getRowData',dt.rowId);
									var row = dt.rowData;
									row.name = d.name;
									publishEvent(row, renamePublishFlow);
								}
							},{
								id : "delete",
								icon : "ui-icon tempo-ui-icon tempo-ui-icon-delete",
								title : TempoUtils.locale("mine.publish-published-flow-grid-optdel"),
								click : function(e,dt){	     
									var row = dt.rowData;
									deletePublishFlow(row);
								}
							},{
								id : "view",
								icon: "ui-icon tempo-ui-icon tempo-ui-icon-linkage",
								title: TempoUtils.locale("mine.publish-published-flow-grid-optview"),
								click:function(e,dt){	     
									var row = dt.rowData;
									viewPublishFlow(row);
								}
							}]
						}]
			});
		}
		this.grid.jqGrid('clearGridData');
		if(data && data.length > 0){
			for (var i = 0; i < data.length; i++) {
				this.grid.jqGrid('addRowData', data[i].id, data[i], i);
			}
		}
	}
	var initPublishFlowGrid = this.initPublishFlowGrid;
	
	/**
	 * 删除发布
	 */
	var deletePublishFlow = function(data){
		var flowId = data.id;
		
		$.ajax({
			url:contextPath+"/api/ai/mine/publish/deletePublish",
			data:{
				id : flowId
			},
			dataType:'json',
			type:'post',
			success:function(result){
				if(result){
					$('#mine-published-grid').jqGrid('delRowData',flowId);
				}else{
					TempoUtils.showTip(TempoUtils.locale("mine.deletePublishError"));
				}
			}
		});
	}
	
	/**
	 * 查看流程图
	 */
	var viewPublishFlow = function(data){
		$.ajax({
			url:contextPath+"/api/ai/mine/publish/getFlowGraphData",
			data:{
				id : data.id
			},
			dataType:'json',
			type:'post',
			success:function(result){
				if(result){
					var viewDialog = $('<div>');
					viewDialog.window({title: TempoUtils.locale("mine.publish-flowGraph"),autoMax: true, allowMax: true, height:600,width:1000});
					viewDialog.window('option', 'allowMax', false);
					var graph = $('<div class="graph">').appendTo(viewDialog).css({height :'100%', width : '100%'});
					var panel = $('<div>').addClass('ui-layout-center').appendTo(graph);
					panel.flowpanel({
						withLogger : false,
						id : 'deploy-flowgraph'
					});
					var board = panel.flowpanel('getBoard');
					renderBoard(result, board, false, data.name);
					panel.flowpanel('setNavigatorRoot')
					panel.flowpanel('loaded');
					// board.miningboard("updateSize");
				}
			}
		});
		
	}
	
	var renamePublishFlow = function(dialog, data, name){
		if(name == data.name){
			dialog.dialog("destroy");
			return;
		}
		if(name &&  name.length > 0){
			$.ajax({
				url:contextPath+"/api/ai/mine/publish/renamePublish",
				data:{
					id : data.id,
					name : name,
					sceneId : analyseId
				},
				dataType:'json',
				type:'post',
				success:function(result){
					if(result && result.success){
						dialog.dialog("destroy");
						data.name = name;
						delete data.opt;
						$('#mine-published-grid').jqGrid('setRowData',data.id, data);
						
					}else{
						var errorCode = result.data;
						//保存失败
						if(errorCode == 0){
							$("<div/>").alert({msg : TempoUtils.locale("mine.publish-savefailed"), height : 280});
						}else{
							//名称重复
							$("<div/>").alert({msg : TempoUtils.locale("mine.publish-nameexists"), height : 280});
						}
					}
				}
			});
		}else{
			$("<div/>").alert({msg : TempoUtils.locale("mine.publish-emptyname"), height : 280});
		}
		
	}
}